package org.meetunexpectedly.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * @Description: 热度排行榜
 * @Author: pupil
 * @Date: 2024/08/30 下午 3:18
 */
@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode
public class HotVideo implements Serializable {

    private static final long serialVersionUID = 1L;

    // 格式化后的热度
    private String hotFormat;

    // 热度
    private Double hot;

    // 视频id
    private Long videoId;

    // 视频标题
    private String title;


    public HotVideo(Double hot, Long videoId, String title) {
        this.hot = hot;
        this.videoId = videoId;
        this.title = title;
    }

    /**
     * 获取格式化后的热度
     * 0.0万 的格式
     */
    public void hotFormat() {
        BigDecimal bigDecimal = new BigDecimal(this.getHot());

        if (bigDecimal.compareTo(new BigDecimal("10000")) < 0) {
            DecimalFormat format = new DecimalFormat("0");
            format.setRoundingMode(RoundingMode.HALF_UP); // 向上取整，四舍五入到最近的整数
            String hotFormat = format.format(bigDecimal);
            this.setHotFormat(hotFormat);
        } else {
            BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"));
            DecimalFormat format = new DecimalFormat("0.0");
            format.setRoundingMode(RoundingMode.HALF_UP); // 向上取整，四舍五入到最近的整数
            String hotFormat = format.format(decimal);
            this.setHotFormat(hotFormat + "万");
        }

    }


}
